home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / obsolete / sigma.pro < prev    next >
Encoding:
Text File  |  1997-07-08  |  2.6 KB  |  105 lines

  1. ; $Id: sigma.pro,v 1.2 1993/05/28 16:11:51 dave Exp $
  2.  
  3. FUNCTION SIGMA,ARRAY,N_PAR,DIMENSION
  4. ;+
  5. ; NAME:
  6. ;    SIGMA
  7. ;
  8. ; PURPOSE:
  9. ;    Calculate the standard deviation value of an array, or calculate the 
  10. ;    standard deviation over one dimension of an array as a function of all
  11. ;    the other dimensions.
  12. ;
  13. ; CATEGORY:
  14. ;    Statistics.
  15. ;
  16. ; CALLING SEQUENCE:
  17. ;    Result = SIGMA(Array)
  18. ;
  19. ;    Result = SIGMA(Array, N_Par)
  20. ;
  21. ;    Result = SIGMA(Array, N_Par, Dimension)
  22. ;
  23. ; INPUTS:
  24. ;    Array:    The input array of any type except string.
  25. ;
  26. ; OPTIONAL INPUT PARAMETERS:
  27. ;    N_Par:    The number of parameters.  The default value is zero.  The 
  28. ;        number of degrees of freedom is N_ELEMENTS(Array) - N_Par.  
  29. ;        The value of sigma varies as one over the square root of the 
  30. ;        number of degrees of freedom.
  31. ;
  32. ;   Dimension:    The dimension to do standard deviation over.
  33. ;
  34. ; OUTPUTS:
  35. ;    SIGMA returns the standard deviation value of the array when called 
  36. ;    with one parameter. 
  37. ;
  38. ;    If DIMENSION is passed, then the result is an array with all the
  39. ;    dimensions of the input array except for the dimension specified,
  40. ;    each element of which is the standard deviation of the corresponding
  41. ;    vector in the input array.
  42. ;
  43. ;    For example, if A is an array with dimensions of (3,4,5), then the
  44. ;    command:
  45. ;
  46. ;        B = SIGMA(A,N,1) 
  47. ;
  48. ;    is equivalent to
  49. ;
  50. ;        B = FLTARR(3,5)
  51. ;        FOR J = 0,4 DO BEGIN
  52. ;            FOR I = 0,2 DO BEGIN
  53. ;            B(I,J) = SIGMA(A(I,*,J), N)
  54. ;            ENDFOR
  55. ;        ENDFOR
  56. ;
  57. ; COMMON BLOCKS:
  58. ;    None.
  59. ;
  60. ; SIDE EFFECTS:
  61. ;    None.
  62. ;
  63. ; RESTRICTIONS:
  64. ;    The dimension specified must be valid for the array passed, 
  65. ;    otherwise the input array is returned as the output array.
  66. ;
  67. ; PROCEDURE:
  68. ;    When DIMENSION is passed, then the function SUM is used.
  69. ;
  70. ; MODIFICATION HISTORY:
  71. ;    William Thompson    Applied Research Corporation
  72. ;    July, 1986        8201 Corporate Drive
  73. ;                Landover, MD  20785
  74. ;    DMS, May, 1993        Removed AVG fcn, use new features of TOTAL.
  75. ;-
  76. ;
  77. ON_ERROR,2                      ;Return to caller if an error occurs
  78. S = SIZE(ARRAY)
  79. IF S(0) EQ 0 THEN BEGIN
  80.    message, 'Variable ARRAY must be an array.', /CONTINUE
  81.    RETURN,ARRAY
  82. ENDIF
  83. IF N_PARAMS(0) EQ 3 THEN BEGIN
  84.     IF ((DIMENSION GE 0) AND (DIMENSION LT S(0))) THEN BEGIN
  85.         m = n_elements(array) / s(dimension+1)
  86.         SIG = SQRT( TOTAL(ARRAY^2,DIMENSION)/m - $
  87.             (TOTAL(ARRAY,DIMENSION)/m)^2 )
  88.         N = S(DIMENSION+1)
  89.     END ELSE BEGIN
  90.         message, 'ARRAY Dimension out of range.', /CONTINUE
  91.         RETURN,ARRAY
  92.     ENDELSE
  93. END ELSE BEGIN
  94.     m = n_elements(array)
  95.     DIFF = ARRAY - TOTAL(array)/m
  96.     SIG = SQRT( TOTAL( DIFF*DIFF )/M)
  97.     N = N_ELEMENTS(ARRAY)
  98. ENDELSE
  99. ;
  100. IF N_PARAMS(0) GE 2 THEN SIG = SIG * SQRT( N / ((N - N_PAR) > 1.) )
  101. ;
  102. RETURN,SIG
  103. END
  104.  
  105.